<template>
    <div class="container" v-if="scoreObj.length != 0">

        <TopBar :title="getTitle" @onClickLeft="onClickLeft"></TopBar>

        <div class="header-top">
            <img :src="IMG_URL + '/head.png'" style="width: 100%;">
        </div>

        <div class="header">
            <div class="header-box">
                <van-row>
                    <van-col span="18">
                        <p>
                            <span class="num">{{ scoreObj.score }}</span>
                            <span class="fen">分</span>
                        </p>
                        <p class="label">投资价值评分</p>
                        <p class="text">评分结果根据下面指标计算得出</p>
                    </van-col>
                    <van-col span="6">
                        <img :src="IMG_URL + '/head-fen.png'" class="score"/>
                    </van-col>
                </van-row>
            </div>
            <div class="header-desc" :class="{'header-desc-dis':!descShow}">
                {{ scoreObj.descr }}
            </div>
            <div class="header-footer" v-if="scoreObj.descr.length > 75">
                <van-icon name="arrow-down" color="#999" size="20" v-show="descShow" @click="descShow = false" />
                <van-icon name="arrow-up" color="#999" size="20" v-show="!descShow"  @click="descShow = true"/>
            </div>
        </div>

        <div class="main">

            <div class="box">
                <img :src="IMG_URL+ '/box-top1.png'" class="top-tip">

                <van-row gutter="10">
                    <van-col span="12">

                        <div class="box-item">
                            <div class="tag" :class="getSz ? '':'tag-2'">
                                <img :src="getSz ? img1 : img2" class="tag-img">
                                <span>{{ getSz ? '符合':'不符合' }}   </span>
                            </div>
                            <p class="box-num" :class="getSz ? '':'box-num2'">{{ infoData.szPETTM }}</p>
                            <p class="box-label">深证市盈率</p>
                            <p class="box-text">推荐标准：深证市盈率 < 20</p>
                        </div>

                    </van-col>
                    <van-col span="12">

                        <div class="box-item">
                            <div class="tag" :class="getTm ? 'tag-2':''">
                                <img :src="getTm ? img2: img1" class="tag-img">
                                <span>{{ getTm ? '不符合':'符合' }}</span>
                            </div>
                            <p class="box-num" :class="getTm ? 'box-num2':''">{{ infoData.stockPETTMStandard }}</p>
                            <p class="box-label">本股TTM市盈率</p>
                            <p class="box-text">推荐标准：本股市盈率 < 15</p>
                        </div>

                    </van-col>
                </van-row>

                <div class="box2">
                    <div class="tag" :class="getDy ? '':'tag-2'">
                        <img :src="getDy ? img1 : img2" class="tag-img">
                        <span>{{ getDy ? '符合':'不符合' }}</span>
                    </div>
                    <div :class="getDy ? 'box2-num':'' ">{{ infoData.stockDYRTTM }}</div>
                    <div class="box2-label">TTM股息率</div>
                    <div class="box2-text">推荐标准：股息率 > 中国10年国债收益</div>
                </div>

            </div>


            <div class="box3">
                <img :src="IMG_URL + '/box-top2.png'" class="top-tip">

                <div class="box3-item">
                    <div class="box3-title">总资产</div>
                    <echart1></echart1>
                </div>

                <div class="van-hairline--top" style="padding-bottom: 1px"></div>

                <echart2></echart2>

                <div class="van-hairline--top"></div>

                <echart3></echart3>

                <div class="van-hairline--top"></div>


                <echart4></echart4>

                <div class="van-hairline--top"></div>

                <echart5></echart5>

                <div class="van-hairline--top"></div>

                <echart6></echart6>

                <div class="van-hairline--top"></div>

                <echart7></echart7>

                <div class="van-hairline--top"></div>

                <div class="box3-item">
                    <div class="box3-title">行业地位及成长性</div>
                    <!--<van-row type="flex" justify="space-between" style="position: absolute;left: 0;right: 0;top: 105px;bottom: 0;height:32px;">
                        <van-col span="12">
                            <div class="echarts-text echarts-left">营业收入增长率</div>
                        </van-col>
                        <van-col span="12">
                            <div class="echarts-text echarts-right">营业收入(万)</div>
                        </van-col>
                    </van-row>-->
                    <echart8></echart8>

                    <div class="collect-group" @click="onClick()">
                        <div class="collect-group-label">
                            <p>判断标准：</p>
                            <p>增长率最好>10%</p>
                        </div>
                    </div>
                </div>

                <div class="van-hairline--top"></div>

                <div class="box3-item">
                    <div class="box3-title">产品竞争力及风险</div>
                    <!--<van-row type="flex" justify="space-between" style="position: absolute;left: 0;right: 0;top: 105px;bottom: 0;">
                        <van-col span="12">
                            <div class="echarts-text echarts-left">毛利率增长性</div>
                        </van-col>
                        <van-col span="12">
                            <div class="echarts-text echarts-right">毛利率(万)</div>
                        </van-col>
                    </van-row>-->
                    <echart9></echart9>

                </div>

                <div class="van-hairline--top"></div>

                <div class="box3-item">
                    <div class="box3-title">成本管控能力</div>
                    <echart10></echart10>
                </div>

                <div class="van-hairline--top"></div>

                <div class="box3-item">
                    <div class="box3-title">现金流含金量</div>

                    <echart11></echart11>

                </div>

                <div class="van-hairline--top"></div>

                <div class="box3-item">
                    <div class="box3-title">整体盈利及持续性</div>

                    <echart12></echart12>

                </div>

                <div class="van-hairline--top"></div>

                <div class="box3-item">
                    <div class="box3-title">公司发展潜力</div>
                    <echart13></echart13>

                </div>

                <div class="van-hairline--top"></div>

                <div class="box3-item">
                    <div class="box3-title">公司分红慷慨度</div>
                    <echart14></echart14>
                </div>

            </div>


        </div>

        <div class="footer">
            <p>股市有风险</p>
            <p>以上分析逻辑及数据仅供参考</p>
            <p>所有数据均来自开源接口，不保证严格准确</p>
        </div>


        <!--弹出开始-->
        <van-popup v-model="show" :style="{ height: '60%',width: '90%' }" closeable round>
            <div class="popup-container">
                <div class="popup-container-title">竞争优势</div>
                <div id="Chart13" :style="{width: '100%', height: '300px'}"></div>
            </div>

        </van-popup>
        <!--弹出结束-->


    </div>
</template>

<script>
    import echart1 from "./echarts/echart1";
    import echart2 from "./echarts/echart2";
    import echart3 from "./echarts/echart3";
    import echart4 from "./echarts/echart4";
    import echart5 from "./echarts/echart5";
    import echart6 from "./echarts/echart6";
    import echart7 from "./echarts/echart7";
    import echart8 from "./echarts/echart8";
    import echart9 from "./echarts/echart9";
    import echart10 from "./echarts/echart10";
    import echart11 from "./echarts/echart11";
    import echart12 from "./echarts/echart12";
    import echart13 from "./echarts/echart13";
    import echart14 from "./echarts/echart14";

    import {goBack} from "../utils/common";

    import {macroInfo,stockScore} from "../api/index";


    let option1 = {
        color: '#6467F0',
        legend: {
            data: ['销售费用率', '期间费用率/毛利率'],
            left: '0',
            top: '0',
            textStyle: {
                color: '#333',
            }
        },
        xAxis: {
            type: 'category',
            data: ['2015', '2016', '2017', '2018', '2019']
        },
        yAxis: {
            type: 'value'
        },
        series: [
            {
                name: '销售费用率',
                data: [150, 230, 224, 218, 135],
                type: 'line',
                itemStyle: {
                    color: '#FA5151'
                },
                lineStyle: {
                    normal: {
                        color: '#FA5151'
                    }
                },
                areaStyle: {
                    color: '#FA5151',
                    opacity: 0.1
                }
            },
            {
                name: '期间费用率/毛利率',
                data: [50, 80, 100, 150, 180, 220],
                type: 'line',
                itemStyle: {
                    color: '#6467F0'
                },
                lineStyle: {
                    normal: {
                        color: '#6467F0'
                    }
                },
                areaStyle: {
                    color: '#6467F0',
                    opacity: 0.1
                }
            }
        ]
    };

    export default {
        name: 'Home',
        components: {
            echart1, echart2, echart3, echart4, echart5, echart6, echart7, echart8, echart9, echart10, echart11,echart12, echart13, echart14
        },
        data() {
            return {
                show: false,
                img1: this.IMG_URL + '/tag-1.png',
                img2: this.IMG_URL + '/tag-2.png',
                infoData: {},
                scoreObj: '',
                queryData: {},
                descShow: false
            }
        },
        computed: {
            getSz(val){
                return this.infoData.szPETTM < 20;
            },
            getTm() {
                return this.infoData.stockPETTMStandard < 15;
            },
            getDy(){
                return this.stockDYRTTM > this.chinaDebtIncomeRatio
            },
            getTitle(){
                let code = this.queryData && this.$route.query.tscode  ? this.$route.query.tscode.split('.')[1]: '';
                return `${this.queryData.name}(${code})`
            }
        },
        mounted() {
            this.queryData = this.$route.query || {};

            this.init();
            this.init2();
            this.init3();
        },
        methods: {
            onClickLeft() {
                goBack();
            },
            onClick() {
                this.show = true;
                this.$nextTick(() => {
                    let Chart13 = this.$echarts.init(document.getElementById('Chart13'));
                    Chart13.setOption(option);
                });
            },
            init() {

                macroInfo(this.queryData.tscode).then(res=>{
                    this.infoData = res;
                });


                return
                // 基于准备好的dom，初始化echarts实例
                /*let Chart1 = this.$echarts.init(document.getElementById('Chart1'));
                let Chart2 = this.$echarts.init(document.getElementById('Chart2'));
                let Chart6 = this.$echarts.init(document.getElementById('Chart6'));
                let Chart7 = this.$echarts.init(document.getElementById('Chart7'));




                Chart1.setOption(option);
                Chart2.setOption(option);
                Chart6.setOption(option);
                Chart7.setOption(option);*/

            },
            async init2() {

                await stockScore(this.queryData.tscode).then(res=>{
                    this.scoreObj = res;
                    if(res && res.descr){
                        this.descShow = res.descr.length > 75 ? true: false;
                    }
                });

                return



                /*let Chart4 = this.$echarts.init(document.getElementById('Chart4'));
                let Chart5 = this.$echarts.init(document.getElementById('Chart5'));
                let color = new this.$echarts.graphic.LinearGradient(
                    1, 0, 0, 1,
                    [
                        {offset: 0, color: '#4765FA'},
                        {offset: 0.4, color: '#14E394'},
                        {offset: 1, color: '#14E394'}
                    ]
                );


                let option = {
                    color: color,
                    itemStyle: {
                        color: '#58D9F9',
                        shadowColor: 'rgba(0,138,255,0.45)',
                        shadowBlur: 10,
                        shadowOffsetX: 2,
                        shadowOffsetY: 2
                    },
                    series: [
                        {
                            type: 'gauge',
                            startAngle: 180,
                            endAngle: 0,
                            radius: 130,
                            center: ['50%', '97%'],
                            height: '260px',
                            progress: {
                                show: true
                            },
                            axisLine: {
                                show: true,
                                lineStyle: {
                                    width: 10,
                                    opacity: 1
                                }
                            },
                            axisTick: {  //刻度线
                                show: true,
                                lineStyle: {
                                    color: '#D8D8D8'
                                }
                                /!* length: 20,
                                 splitNumber: 2,
                                 lineStyle: {
                                     color: [[0.25, '#FF6E76'], [0.5, '#FDDD60'], [0.75, '#58D9F9'], [1, '#7CFFB2']],
                                     width: 5
                                 }*!/
                            },
                            axisLabel: {
                                distance: -38,
                                show: false
                            },
                            splitLine: { // 分隔线
                                show: true,
                                lineStyle: {
                                    width: 2,
                                    color: '#D8D8D8'
                                }
                                /!*length: 20,
                                splitNumber: 2,
                                lineStyle: {
                                    color: '#D8D8D8',
                                    width: 5
                                }*!/
                            },
                            pointer: { //指针
                                show: true,
                                icon: 'path://M65.582671 288.791335l446.417329 446.41733 446.417329-446.41733z',
                                length: '8%',
                                width: 8,
                                height: 10,
                                offsetCenter: [0, '-103%'],
                                itemStyle: {
                                    color: '#25B8B7'
                                }
                            },
                            title: {
                                fontSize: 18,
                                offsetCenter: [0, '-50%']
                            },
                            detail: {
                                offsetCenter: [0, '-20'],
                                valueAnimation: true,
                                formatter: function (value) {
                                    return '{value|' + value.toFixed(0) + '}{unit|%}';
                                },
                                rich: {
                                    value: {
                                        fontSize: 50,
                                        fontWeight: 'bolder',
                                        color: '#333333'
                                    },
                                    unit: {
                                        fontSize: 18,
                                        color: '#333333',
                                        padding: [0, 0, -12, 0]
                                    }
                                }
                            },
                            data: [
                                {
                                    name: '差',
                                    value: 60,
                                }
                            ]
                        }
                    ]
                };


                Chart4.setOption(option);
                Chart5.setOption(option);*/
            },
            init3() {


                /* let Chart10 = this.$echarts.init(document.getElementById('Chart10'));
                 let Chart11 = this.$echarts.init(document.getElementById('Chart11'));
                 let Chart12 = this.$echarts.init(document.getElementById('Chart12'));


                 Chart10.setOption(option1);
                 Chart11.setOption(option1);
                 Chart12.setOption(option1);*/

            }
        }
    }
</script>

<style scoped lang="less">


    .container {
        width: 100vw;
        min-height: 100vh;
        background-color: #f5f5f5;
    }

    /deep/ .van-nav-bar .van-icon {
        color: #000000;
        font-size: 18px;
    }


    .tag {
        position: absolute;
        right: 0;
        top: 0;
        width: 62px;
        height: 24px;
        background: linear-gradient(94deg, rgba(255, 240, 242, 0) 0%, #FFDDE0 100%);
        border-radius: 0px 0px 0px 13px;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 12px;
        color: #FA5151;

        .tag-img {
            width: 15px;
            height: 15px;
            margin-right: 4px;
        }
    }

    .tag-2 {
        background: linear-gradient(270deg, #DCDCDC 0%, rgba(240, 240, 240, 0) 100%);
        color: #666666;
    }

    .echarts-text {
        font-size: 12px;
        zoom: 0.9;
        color: #999999;
    }

    .echarts-left {
        text-align: left;
    }

    .echarts-right {
        text-align: right;
    }

    .van-hairline--top {
        margin-top: 30px;
    }


    .facial-group {
        text-align: center;
        padding: 14px 25px 0 30px;
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        font-size: 13px;
        color: #666666;

        p {
            margin-top: 4px;
        }
    }

    .facial-group-top {
        margin-top: -50px;
    }

    .header-top{
        width: 100%;
        height: 240px;
    }


    .header {
        position: relative;
        top: -100px;
        left: 10px;
        width: calc(100% - 20px);
        height: auto;
        background-color: #FFFFFF;
        border-radius: 6px;
        overflow: hidden;
        padding-bottom: 14px;

        .header-box {
            position: relative;
            width: calc(100% - 33px);
            height: auto;
            padding-left: 20px;
            padding-right: 13px;
            padding-top: 14px;
            background: url("https://lingdaoyi.net/img/head-box.png") no-repeat;
            background-size: 100% 100%;

            .num {
                width: 50px;
                height: 46px;
                font-size: 42px;
                font-weight: bold;
                color: #6467F0;
                line-height: 46px;
            }

            .fen {
                color: #6467F0;
                font-size: 14px;
            }

            .label {
                font-size: 14px;
                font-weight: 500;
                color: #333333;
            }

            .text {
                font-size: 12px;
                color: #999999;
                margin-top: 6px;
            }

            .score {
                position: absolute;
                top: 0;
                right: 13px;
                width: 52px;
                height: 80px;
            }
        }
        .header-desc{
            padding: 0 14px 14px 20px;
            margin-top: 24px;
            font-size: 12px;
            color: #999999;
            line-height: 16px;
            height: 20px;
            text-overflow: -o-ellipsis-lastline;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            line-clamp: 2;
            -webkit-box-orient: vertical;
        }

        .header-desc-dis{
            height: auto;
            display: inline-block;
        }

        .header-footer{
            text-align: center;
        }

    }

    .main {
        position: relative;
        top: -90px;
        padding: 0 10px;

        .top-tip {
            width: 169px;
            height: 40px;
        }

        .box {
            padding: 0 10px 10px 10px;
            text-align: center;
            width: calc(100% - 20px);
            background: #FFFFFF;
            border-radius: 6px;


            .box-item {
                position: relative;
                background: #F9FBFF;
                padding: 22px 0 17px 0;
                margin-top: 24px;

                .box-num {
                    font-size: 34px;
                    font-weight: bold;
                    color: #FA5151;
                }

                .box-num2 {
                    color: #333333;
                }

                .box-label {
                    font-size: 14px;
                    font-weight: 500;
                    color: #333333;
                    margin-top: 8px;
                    margin-bottom: 10px;
                }

                .box-text {
                    font-size: 10px;
                    font-weight: 400;
                    color: #999999;
                }


            }

        }

        .box2 {
            position: relative;
            margin-top: 10px;
            padding-top: 22px;
            padding-bottom: 17px;
            width: 100%;
            text-align: center;
            background: #F9FBFF;
            font-size: 34px;
            font-weight: bold;

            .box2-num {
                color: #FA5151;
            }

            .box2-label {
                font-size: 14px;
                font-weight: 500;
                color: #333333;
                margin-top: 8px;
                margin-bottom: 10px;
            }

            .box2-text {
                font-size: 12px;
                color: #999999;
                zoom: 0.9;
            }

        }

        .box3 {
            position: relative;
            margin-top: 10px;
            text-align: center;
            width: calc(100% - 20px);
            height: auto;
            padding: 0 10px 32px 10px;
            background: #FFFFFF;
            border-radius: 6px;

            .box3-item {
                position: relative;
            }

            .box3-title {
                font-size: 18px;
                font-weight: 500;
                color: #333333;
                text-align: left;
                padding-bottom: 24px;
                padding-top: 24px;
            }

            .line-group {
                width: 80vw;
                margin: 0 auto 24px auto;
                font-size: 16px;
                color: #999999;

                .line-box {
                    width: 100%;
                    height: 10px;
                    background: #EEF4FF;
                }

                .line-1 {
                    background-color: #FA5151;
                }

                .line-2 {
                    background-color: #FFC509;
                }

                .line-3 {
                    background-color: #16DE98;
                }

                .line-text {
                    position: relative;
                    top: 9px;
                }

                .line-text-1 {
                    color: #FA5151;
                }

                .line-text-2 {
                    color: #FFC509;
                }

                .line-text-3 {
                    color: #16DE98;
                }


            }

            .box3-group-label {
                margin-top: 18px;
                padding: 8px 10px;
                text-align: left;
                zoom: 0.9;
                font-size: 10px;
                line-height: 15px;
                color: #999999;
                background: #F9FBFF;
            }


        }
    }

    .footer {
        position: relative;
        top: -50px;
        text-align: center;
        font-size: 12px;
        font-weight: 400;
        color: #999999;
        line-height: 18px;
    }

</style>
